package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BieAccessCard;
import com.ruoyi.system.service.IBieAccessCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门禁卡Controller
 * 
 * @author zxl
 * @date 2021-05-03
 */
@RestController
@RequestMapping("/system/card")
public class BieAccessCardController extends BaseController
{
    @Autowired
    private IBieAccessCardService bieAccessCardService;

    /**
     * 查询门禁卡列表
     */
    @PreAuthorize("@ss.hasPermi('system:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(BieAccessCard bieAccessCard)
    {
        startPage();
        List<BieAccessCard> list = bieAccessCardService.selectBieAccessCardList(bieAccessCard);
        return getDataTable(list);
    }

    /**
     * 导出门禁卡列表
     */
    @PreAuthorize("@ss.hasPermi('system:card:export')")
    @Log(title = "门禁卡", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BieAccessCard bieAccessCard)
    {
        List<BieAccessCard> list = bieAccessCardService.selectBieAccessCardList(bieAccessCard);
        ExcelUtil<BieAccessCard> util = new ExcelUtil<BieAccessCard>(BieAccessCard.class);
        return util.exportExcel(list, "门禁卡数据");
    }

    /**
     * 获取门禁卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:card:query')")
    @GetMapping(value = "/{accessCardId}")
    public AjaxResult getInfo(@PathVariable("accessCardId") String accessCardId)
    {
        return AjaxResult.success(bieAccessCardService.selectBieAccessCardById(accessCardId));
    }

    /**
     * 新增门禁卡
     */
    @PreAuthorize("@ss.hasPermi('system:card:add')")
    @Log(title = "门禁卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BieAccessCard bieAccessCard)
    {
        return toAjax(bieAccessCardService.insertBieAccessCard(bieAccessCard));
    }

    /**
     * 修改门禁卡
     */
    @PreAuthorize("@ss.hasPermi('system:card:edit')")
    @Log(title = "门禁卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BieAccessCard bieAccessCard)
    {
        return toAjax(bieAccessCardService.updateBieAccessCard(bieAccessCard));
    }

    /**
     * 删除门禁卡
     */
    @PreAuthorize("@ss.hasPermi('system:card:remove')")
    @Log(title = "门禁卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{accessCardIds}")
    public AjaxResult remove(@PathVariable String[] accessCardIds)
    {
        return toAjax(bieAccessCardService.deleteBieAccessCardByIds(accessCardIds));
    }
}
